﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using VCC.Lib.Common;
using System.Web.Security;

namespace VCC.Lib.Helpers
{
    
    public class RoleHelper : AuthorizeAttribute
    {
        public new string Roles;
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
                throw new ArgumentNullException("httpContext");

            if (!httpContext.User.Identity.IsAuthenticated)
                return false;
            //return true;
            string[] userRoles = System.Web.Security.Roles.GetRolesForUser();
            if (userRoles.Contains(RoleSystem.Administrator)) return true;
            foreach (string userRole in userRoles)
            {
                if (userRoles.Contains(Roles))
                {
                    return true;
                }
            }
            httpContext.Session["AccessFail"] = Roles;
            return false;
        }
    }
}
